<?php
	// this section merely lists any bills the user has entered, and tracks who has and hasn't paid
	// if all members have paid, or completed the task, it will no longer appear here
	
	$bills = getBillIDS($_SESSION['username'], "bill");
	
	echo '<div id="billTracking">
			<fieldset>
			<h3>Bills</h3>
			';
			
			//<p>Listed below are any bills you have entered into the Flatshare system.</p>
			//';
	
	if (!$bills || (mysql_numrows($bills) < 1)) {
		echo '<p>You have not entered any bills into the system.</p>';
	}
	else {
		while ($row = mysql_fetch_array($bills)) {
			$users = getBillUsers($row[0]);
			$billcomplete = 1;
			$counter = 0;
			$table[8][2] ;
			
			while ($member = mysql_fetch_array($users)) {
				// get user name, needed for all entries
				
				$name = getUserName($member[0]);
				$table[$counter][0] = $name[0] . ' ' . $name[1];
				
				if ($member[2] == NULL || $member[2] == "") {
					// user has not paid bill
					$billcomplete = 0;
					$table[$counter][1] = "Share: $" . $member[1];
				}
				else {
					if ($member[3] == NULL || $member[3] == "") {
						// user has paid bill, but not been confirmed
						$billcomplete = 0;
						$table[$counter][1] = "Paid on: <br />" . $member[2];
					}
					else {
						// user has paid bill and been confirmed
						$table[$counter][1] = "Confirmed on: <br />" . $member[3];
					}
				}
				$counter = $counter + 1;
			}
			
			
			
			if (!$billcomplete) {
				// code if at least one member has not paid or is unconfirmed
				echo '<p><strong>' . $row[1] . '</strong></p>
						<table>
						';
				for ($i = 0; $i < $counter; $i++) {
					echo '<tr>
							<td>' . $table[$i][0] . '</td>
							<td>' . $table[$i][1] . '</td>
							</tr>';	
				}
				echo '</table><br />
						';
			}
		}
	}
	
	echo '</fieldset>
			</div>
			';
	
	// ****** CHORES
	
	$chores = getBillIDS($_SESSION['username'], "chore");
	
	
	echo '<div id="choreTracking">
			<fieldset>
			<h3>Chores</h3>
			';
			
	if (!$chores || (mysql_numrows($chores) < 1)) {
		echo '<p>You have not entered any chores into the system.</p>';
	}
	else {
		while ($row = mysql_fetch_array($chores)) {
			$users = getChoreUsers($row[0]);
			$chorecomplete = 1;
			$counter = 0;
			$table[8][2] ;
			
			while ($member = mysql_fetch_array($users)) {
				// get user name, needed for all entries
				
				$name = getUserName($member[0]);
				$table[$counter][0] = $name[0] . ' ' . $name[1];
				
				if ($member[1] == NULL || $member[1] == "") {
					// user has not paid bill
					$chorecomplete = 0;
					$table[$counter][1] = "Not Completed";
				}
				else {
					$table[$counter][1] = "Completed";
				}
				$counter = $counter + 1;
			}
			
			
			
			if (!$chorecomplete) {
				// code if at least one member has not paid or is unconfirmed
				echo '<p><strong>' . $row[1] . '</strong></p>
						<table>
						';
				for ($i = 0; $i < $counter; $i++) {
					echo '<tr>
							<td>' . $table[$i][0] . '</td>
							<td>' . $table[$i][1] . '</td>
							</tr>';	
				}
				echo '</table><br />
						';
			}
		}
	}
	
	echo '</fieldset>
			</div>
			';
?>